package com.ruoyi.mall.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.entity.MallCategoryProperty;
import com.ruoyi.mall.service.IMallCategoryPropertyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类属性中间Controller
 * 
 * @author ruoyi
 * @date 2020-05-21
 */
@Controller
@RequestMapping("/mall/categoryProperty")
public class MallCategoryPropertyController extends BaseController
{
    private String prefix = "mall/categoryProperty";

    @Autowired
    private IMallCategoryPropertyService mallCategoryPropertyService;

    @RequiresPermissions("mall:categoryProperty:view")
    @GetMapping()
    public String categoryProperty()
    {
        return prefix + "/categoryProperty";
    }

    /**
     * 查询分类属性中间列表
     */
    @RequiresPermissions("mall:categoryProperty:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallCategoryProperty mallCategoryProperty)
    {
        startPage();
        List<MallCategoryProperty> list = mallCategoryPropertyService.selectMallCategoryPropertyList(mallCategoryProperty);
        return getDataTable(list);
    }

    /**
     * 导出分类属性中间列表
     */
    @RequiresPermissions("mall:categoryProperty:export")
    @Log(title = "分类属性中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallCategoryProperty mallCategoryProperty)
    {
        List<MallCategoryProperty> list = mallCategoryPropertyService.selectMallCategoryPropertyList(mallCategoryProperty);
        ExcelUtil<MallCategoryProperty> util = new ExcelUtil<MallCategoryProperty>(MallCategoryProperty.class);
        return util.exportExcel(list, "categoryProperty");
    }

    /**
     * 新增分类属性中间
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分类属性中间
     */
    @RequiresPermissions("mall:categoryProperty:add")
    @Log(title = "分类属性中间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallCategoryProperty mallCategoryProperty)
    {
        return toAjax(mallCategoryPropertyService.insertMallCategoryProperty(mallCategoryProperty));
    }

    /**
     * 修改分类属性中间
     */
    @GetMapping("/edit/{categoryPropertyId}")
    public String edit(@PathVariable("categoryPropertyId") Long categoryPropertyId, ModelMap mmap)
    {
        MallCategoryProperty mallCategoryProperty = mallCategoryPropertyService.selectMallCategoryPropertyById(categoryPropertyId);
        mmap.put("mallCategoryProperty", mallCategoryProperty);
        return prefix + "/edit";
    }

    /**
     * 修改保存分类属性中间
     */
    @RequiresPermissions("mall:categoryProperty:edit")
    @Log(title = "分类属性中间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallCategoryProperty mallCategoryProperty)
    {
        return toAjax(mallCategoryPropertyService.updateMallCategoryProperty(mallCategoryProperty));
    }

    /**
     * 删除分类属性中间
     */
    @RequiresPermissions("mall:categoryProperty:remove")
    @Log(title = "分类属性中间", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallCategoryPropertyService.deleteMallCategoryPropertyByIds(ids));
    }
}
